﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AgilePlannerDT.Data.Impl
{
    public class MouseMoveDataObject :MouseMove
    {
        #region property
        string name;
        int eventType, clientID, touchID;
        double locationX, locationY,newWidth,newHeight;
        object thirdPartyObject = null; 
        long cardID;
        #endregion 

        #region constructor
        public MouseMoveDataObject():this(0,0,"",0,0,MouseMoveConstants.PURE_MOUSEMOVE,0)
        {
        }
        public MouseMoveDataObject(int clientID,int touchID, string name, double locationX, double locationY, int eventType,long cardID)
        {
            this.clientID = clientID;
            this.name = name;
            this.locationX = locationX;
            this.locationY = locationY;
            this.eventType = eventType;
            this.cardID = cardID;
            this.thirdPartyObject = null;
            this.touchID =touchID;
        }

        public MouseMoveDataObject(int clientID,int touchID, string name, double locationX, double locationY, int eventType, object thirdPartyObject)
        {
            this.clientID = clientID;
            this.name = name;
            this.locationX = locationX;
            this.locationY = locationY;
            this.eventType = eventType;
            this.touchID = touchID;
            this.thirdPartyObject = thirdPartyObject;
           
        }
        #endregion 
        #region MouseMove Members

        string MouseMove.Name
        {
            get
            {
                return this.name;
            }
            set
            {
                this.name = value;
            }
        }

        double MouseMove.LocationX
        {
            get
            {
                return this.locationX;
            }
            set
            {
                this.locationX = value;
            }
        }

        double MouseMove.LocationY
        {
            get
            {
                return this.locationY;
            }
            set
            {
                this.locationY = value;
            }
        }

        int MouseMove.EventType
        {
            get
            {
                return this.eventType;
            }
            set
            {
                if(value!=MouseMoveConstants.PURE_MOUSEMOVE&&value!=MouseMoveConstants.RESIZE_MOUSEMOVE&&value!=MouseMoveConstants.DRAG_MOUSEMOVE)
                   throw new InvalidOperationException();
                else
                {
                    this.eventType = value;
                }
            }
        }

        int MouseMove.ClientID
        {
            get
            {
                return this.clientID;
            }
            set
            {
                this.clientID = value;
            }
        }

        int MouseMove.TouchID
        {
            get
            {
                return this.touchID;
            }
            set
            {
                this.touchID = value;
            }
        }

        #endregion

        #region MouseMove Members


        long MouseMove.CardID
        {
            get
            {
                return this.cardID;
            }
            set
            {
                this.cardID = value;
            }
        }

        object MouseMove.ThirdPartyObject
        {
            get
            {
                return this.thirdPartyObject;
            }
        }

        #endregion

        #region IXmlSerializable Members

        public System.Xml.Schema.XmlSchema GetSchema()
        {
            throw new NotImplementedException();
        }

        public void ReadXml(System.Xml.XmlReader reader)
        {
            this.clientID = Convert.ToInt32(reader.GetAttribute("clientID"));
            this.name = reader.GetAttribute("name");
            this.locationX = Convert.ToDouble(reader.GetAttribute("locationX"));
            this.locationY = Convert.ToDouble(reader.GetAttribute("locationY"));
            this.touchID = Convert.ToInt32(reader.GetAttribute("touchID"));
            while(reader.Read())
            {
                if (reader.NodeType == System.Xml.XmlNodeType.Element&&reader.LocalName.Equals("CardDrag"))
                {
                    CardPositionSynchronizationDataObject newThirdParty = new CardPositionSynchronizationDataObject();
                    newThirdParty.ReadXml(reader);
                    this.thirdPartyObject = newThirdParty;
                    break;
                }
                if (reader.NodeType == System.Xml.XmlNodeType.Element && reader.LocalName.Equals("CardResize"))
                {
                    CardSizeSynchronizationDataObject newThirdParty = new CardSizeSynchronizationDataObject();
                    newThirdParty.ReadXml(reader);
                    this.thirdPartyObject = newThirdParty;
                    break;
                }

            }

        }
        //wait to deal with the drag and resize event
        public void WriteXml(System.Xml.XmlWriter writer)
        {
            writer.WriteStartElement("MouseMove");
            writer.WriteAttributeString("clientID", this.clientID.ToString());
            writer.WriteAttributeString("name", this.name);
            writer.WriteAttributeString("locationX", ((int)this.locationX).ToString());
            writer.WriteAttributeString("locationY", ((int)this.locationY).ToString());
            writer.WriteAttributeString("touchID", this.touchID.ToString());
            if (this.eventType == MouseMoveConstants.DRAG_MOUSEMOVE)
            {
                ((CardPoistionSynchronization)(this.thirdPartyObject)).WriteXml(writer);
              
            }
            if (this.eventType == MouseMoveConstants.RESIZE_MOUSEMOVE)
            {
                ((CardSizeSynchronization)(this.thirdPartyObject)).WriteXml(writer);
            }
            writer.WriteEndElement();
        }

        #endregion
    }
}
